package com.billow.book.api;

import com.billow.book.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

@Slf4j
public class MyThread extends Thread {

    @Override
    public void run() {
        String key = "aaa";

        RedissonClient redissonClient = SpringContextUtil.getBean(RedissonClient.class);

        RLock lock2 = redissonClient.getLock(key);
        try {
            if (lock2.tryLock()) {
                log.info("22222222222222");
                RLock lock3 = redissonClient.getLock(key);
                try {
                    if (lock3.tryLock()) {
                        log.info("33333333333");
                    }
                } finally {
                    if (lock3 != null && lock3.isHeldByCurrentThread()) {
                        lock3.unlock();
                    }
                }
            }
        } finally {
            if (lock2 != null && lock2.isHeldByCurrentThread()) {
                lock2.unlock();
            }
        }
        log.info("runrunrunrunrun");
    }
}
